<!DOCTYPE html>
<html>
<!-- Created by GNU Texinfo 7.1, https://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<!-- Copyright © 1988-2023 Free Software Foundation, Inc.

Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with the
Invariant Sections being "Funding Free Software", the Front-Cover
Texts being (a) (see below), and with the Back-Cover Texts being (b)
(see below).  A copy of the license is included in the section entitled
"GNU Free Documentation License".

(a) The FSF's Front-Cover Text is:

A GNU Manual

(b) The FSF's Back-Cover Text is:

You have freedom to copy and modify this GNU Manual, like GNU
     software.  Copies published by the Free Software Foundation raise
     funds for GNU development. -->
<title>Named Address Spaces (GNU Compiler Collection (GCC) Internals)</title>

<meta name="description" content="Named Address Spaces (GNU Compiler Collection (GCC) Internals)">
<meta name="keywords" content="Named Address Spaces (GNU Compiler Collection (GCC) Internals)">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<meta name="viewport" content="width=device-width,initial-scale=1">

<link href="index.html" rel="start" title="Top">
<link href="Option-Index.html" rel="index" title="Option Index">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="Target-Macros.html" rel="up" title="Target Macros">
<link href="Misc.html" rel="next" title="Misc">
<link href="D-Language-and-ABI.html" rel="prev" title="D Language and ABI">
<style type="text/css">
<!--
a.copiable-link {visibility: hidden; text-decoration: none; line-height: 0em}
div.example {margin-left: 3.2em}
span:hover a.copiable-link {visibility: visible}
strong.def-name {font-family: monospace; font-weight: bold; font-size: larger}
-->
</style>


</head>

<body lang="en">
<div class="section-level-extent" id="Named-Address-Spaces">
<div class="nav-panel">
<p>
Next: <a href="Misc.html" accesskey="n" rel="next">Miscellaneous Parameters</a>, Previous: <a href="D-Language-and-ABI.html" accesskey="p" rel="prev">D ABI parameters</a>, Up: <a href="Target-Macros.html" accesskey="u" rel="up">Target Description Macros and Functions</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<h3 class="section" id="Adding-support-for-named-address-spaces"><span>18.30 Adding support for named address spaces<a class="copiable-link" href="#Adding-support-for-named-address-spaces"> &para;</a></span></h3>
<a class="index-entry-id" id="index-named-address-spaces"></a>

<p>The draft technical report of the ISO/IEC JTC1 S22 WG14 N1275
standards committee, <cite class="cite">Programming Languages - C - Extensions to
support embedded processors</cite>, specifies a syntax for embedded
processors to specify alternate address spaces.  You can configure a
GCC port to support section 5.1 of the draft report to add support for
address spaces other than the default address space.  These address
spaces are new keywords that are similar to the <code class="code">volatile</code> and
<code class="code">const</code> type attributes.
</p>
<p>Pointers to named address spaces can have a different size than
pointers to the generic address space.
</p>
<p>For example, the SPU port uses the <code class="code">__ea</code> address space to refer
to memory in the host processor, rather than memory local to the SPU
processor.  Access to memory in the <code class="code">__ea</code> address space involves
issuing DMA operations to move data between the host processor and the
local processor memory address space.  Pointers in the <code class="code">__ea</code>
address space are either 32 bits or 64 bits based on the
<samp class="option">-mea32</samp> or <samp class="option">-mea64</samp> switches (native SPU pointers are
always 32 bits).
</p>
<p>Internally, address spaces are represented as a small integer in the
range 0 to 15 with address space 0 being reserved for the generic
address space.
</p>
<p>To register a named address space qualifier keyword with the C front end,
the target may call the <code class="code">c_register_addr_space</code> routine.  For example,
the SPU port uses the following to declare <code class="code">__ea</code> as the keyword for
named address space #1:
</p><div class="example smallexample">
<pre class="example-preformatted">#define ADDR_SPACE_EA 1
c_register_addr_space (&quot;__ea&quot;, ADDR_SPACE_EA);
</pre></div>

<dl class="first-deftypefn">
<dt class="deftypefn" id="index-TARGET_005fADDR_005fSPACE_005fPOINTER_005fMODE"><span class="category-def">Target Hook: </span><span><code class="def-type">scalar_int_mode</code> <strong class="def-name">TARGET_ADDR_SPACE_POINTER_MODE</strong> <code class="def-code-arguments">(addr_space_t <var class="var">address_space</var>)</code><a class="copiable-link" href="#index-TARGET_005fADDR_005fSPACE_005fPOINTER_005fMODE"> &para;</a></span></dt>
<dd><p>Define this to return the machine mode to use for pointers to
<var class="var">address_space</var> if the target supports named address spaces.
The default version of this hook returns <code class="code">ptr_mode</code>.
</p></dd></dl>

<dl class="first-deftypefn">
<dt class="deftypefn" id="index-TARGET_005fADDR_005fSPACE_005fADDRESS_005fMODE"><span class="category-def">Target Hook: </span><span><code class="def-type">scalar_int_mode</code> <strong class="def-name">TARGET_ADDR_SPACE_ADDRESS_MODE</strong> <code class="def-code-arguments">(addr_space_t <var class="var">address_space</var>)</code><a class="copiable-link" href="#index-TARGET_005fADDR_005fSPACE_005fADDRESS_005fMODE"> &para;</a></span></dt>
<dd><p>Define this to return the machine mode to use for addresses in
<var class="var">address_space</var> if the target supports named address spaces.
The default version of this hook returns <code class="code">Pmode</code>.
</p></dd></dl>

<dl class="first-deftypefn">
<dt class="deftypefn" id="index-TARGET_005fADDR_005fSPACE_005fVALID_005fPOINTER_005fMODE"><span class="category-def">Target Hook: </span><span><code class="def-type">bool</code> <strong class="def-name">TARGET_ADDR_SPACE_VALID_POINTER_MODE</strong> <code class="def-code-arguments">(scalar_int_mode <var class="var">mode</var>, addr_space_t <var class="var">as</var>)</code><a class="copiable-link" href="#index-TARGET_005fADDR_005fSPACE_005fVALID_005fPOINTER_005fMODE"> &para;</a></span></dt>
<dd><p>Define this to return nonzero if the port can handle pointers
with machine mode <var class="var">mode</var> to address space <var class="var">as</var>.  This target
hook is the same as the <code class="code">TARGET_VALID_POINTER_MODE</code> target hook,
except that it includes explicit named address space support.  The default
version of this hook returns true for the modes returned by either the
<code class="code">TARGET_ADDR_SPACE_POINTER_MODE</code> or <code class="code">TARGET_ADDR_SPACE_ADDRESS_MODE</code>
target hooks for the given address space.
</p></dd></dl>

<dl class="first-deftypefn">
<dt class="deftypefn" id="index-TARGET_005fADDR_005fSPACE_005fLEGITIMATE_005fADDRESS_005fP"><span class="category-def">Target Hook: </span><span><code class="def-type">bool</code> <strong class="def-name">TARGET_ADDR_SPACE_LEGITIMATE_ADDRESS_P</strong> <code class="def-code-arguments">(machine_mode <var class="var">mode</var>, rtx <var class="var">exp</var>, bool <var class="var">strict</var>, addr_space_t <var class="var">as</var>)</code><a class="copiable-link" href="#index-TARGET_005fADDR_005fSPACE_005fLEGITIMATE_005fADDRESS_005fP"> &para;</a></span></dt>
<dd><p>Define this to return true if <var class="var">exp</var> is a valid address for mode
<var class="var">mode</var> in the named address space <var class="var">as</var>.  The <var class="var">strict</var>
parameter says whether strict addressing is in effect after reload has
finished.  This target hook is the same as the
<code class="code">TARGET_LEGITIMATE_ADDRESS_P</code> target hook, except that it includes
explicit named address space support.
</p></dd></dl>

<dl class="first-deftypefn">
<dt class="deftypefn" id="index-TARGET_005fADDR_005fSPACE_005fLEGITIMIZE_005fADDRESS"><span class="category-def">Target Hook: </span><span><code class="def-type">rtx</code> <strong class="def-name">TARGET_ADDR_SPACE_LEGITIMIZE_ADDRESS</strong> <code class="def-code-arguments">(rtx <var class="var">x</var>, rtx <var class="var">oldx</var>, machine_mode <var class="var">mode</var>, addr_space_t <var class="var">as</var>)</code><a class="copiable-link" href="#index-TARGET_005fADDR_005fSPACE_005fLEGITIMIZE_005fADDRESS"> &para;</a></span></dt>
<dd><p>Define this to modify an invalid address <var class="var">x</var> to be a valid address
with mode <var class="var">mode</var> in the named address space <var class="var">as</var>.  This target
hook is the same as the <code class="code">TARGET_LEGITIMIZE_ADDRESS</code> target hook,
except that it includes explicit named address space support.
</p></dd></dl>

<dl class="first-deftypefn">
<dt class="deftypefn" id="index-TARGET_005fADDR_005fSPACE_005fSUBSET_005fP"><span class="category-def">Target Hook: </span><span><code class="def-type">bool</code> <strong class="def-name">TARGET_ADDR_SPACE_SUBSET_P</strong> <code class="def-code-arguments">(addr_space_t <var class="var">subset</var>, addr_space_t <var class="var">superset</var>)</code><a class="copiable-link" href="#index-TARGET_005fADDR_005fSPACE_005fSUBSET_005fP"> &para;</a></span></dt>
<dd><p>Define this to return whether the <var class="var">subset</var> named address space is
contained within the <var class="var">superset</var> named address space.  Pointers to
a named address space that is a subset of another named address space
will be converted automatically without a cast if used together in
arithmetic operations.  Pointers to a superset address space can be
converted to pointers to a subset address space via explicit casts.
</p></dd></dl>

<dl class="first-deftypefn">
<dt class="deftypefn" id="index-TARGET_005fADDR_005fSPACE_005fZERO_005fADDRESS_005fVALID"><span class="category-def">Target Hook: </span><span><code class="def-type">bool</code> <strong class="def-name">TARGET_ADDR_SPACE_ZERO_ADDRESS_VALID</strong> <code class="def-code-arguments">(addr_space_t <var class="var">as</var>)</code><a class="copiable-link" href="#index-TARGET_005fADDR_005fSPACE_005fZERO_005fADDRESS_005fVALID"> &para;</a></span></dt>
<dd><p>Define this to modify the default handling of address 0 for the
address space.  Return true if 0 should be considered a valid address.
</p></dd></dl>

<dl class="first-deftypefn">
<dt class="deftypefn" id="index-TARGET_005fADDR_005fSPACE_005fCONVERT"><span class="category-def">Target Hook: </span><span><code class="def-type">rtx</code> <strong class="def-name">TARGET_ADDR_SPACE_CONVERT</strong> <code class="def-code-arguments">(rtx <var class="var">op</var>, tree <var class="var">from_type</var>, tree <var class="var">to_type</var>)</code><a class="copiable-link" href="#index-TARGET_005fADDR_005fSPACE_005fCONVERT"> &para;</a></span></dt>
<dd><p>Define this to convert the pointer expression represented by the RTL
<var class="var">op</var> with type <var class="var">from_type</var> that points to a named address
space to a new pointer expression with type <var class="var">to_type</var> that points
to a different named address space.  When this hook it called, it is
guaranteed that one of the two address spaces is a subset of the other,
as determined by the <code class="code">TARGET_ADDR_SPACE_SUBSET_P</code> target hook.
</p></dd></dl>

<dl class="first-deftypefn">
<dt class="deftypefn" id="index-TARGET_005fADDR_005fSPACE_005fDEBUG"><span class="category-def">Target Hook: </span><span><code class="def-type">int</code> <strong class="def-name">TARGET_ADDR_SPACE_DEBUG</strong> <code class="def-code-arguments">(addr_space_t <var class="var">as</var>)</code><a class="copiable-link" href="#index-TARGET_005fADDR_005fSPACE_005fDEBUG"> &para;</a></span></dt>
<dd><p>Define this to define how the address space is encoded in dwarf.
The result is the value to be used with <code class="code">DW_AT_address_class</code>.
</p></dd></dl>

<dl class="first-deftypefn">
<dt class="deftypefn" id="index-TARGET_005fADDR_005fSPACE_005fDIAGNOSE_005fUSAGE"><span class="category-def">Target Hook: </span><span><code class="def-type">void</code> <strong class="def-name">TARGET_ADDR_SPACE_DIAGNOSE_USAGE</strong> <code class="def-code-arguments">(addr_space_t <var class="var">as</var>, location_t <var class="var">loc</var>)</code><a class="copiable-link" href="#index-TARGET_005fADDR_005fSPACE_005fDIAGNOSE_005fUSAGE"> &para;</a></span></dt>
<dd><p>Define this hook if the availability of an address space depends on
command line options and some diagnostics should be printed when the
address space is used.  This hook is called during parsing and allows
to emit a better diagnostic compared to the case where the address space
was not registered with <code class="code">c_register_addr_space</code>.  <var class="var">as</var> is
the address space as registered with <code class="code">c_register_addr_space</code>.
<var class="var">loc</var> is the location of the address space qualifier token.
The default implementation does nothing.
</p></dd></dl>

</div>
<hr>
<div class="nav-panel">
<p>
Next: <a href="Misc.html">Miscellaneous Parameters</a>, Previous: <a href="D-Language-and-ABI.html">D ABI parameters</a>, Up: <a href="Target-Macros.html">Target Description Macros and Functions</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html" title="Index" rel="index">Index</a>]</p>
</div>



</body>
</html>
